/*
    Copyright 2006 Todi.
    Send feedback and suggestions to todi@peerfeeds.com.  
  
    This file is part of Peerfeeds.

    Peerfeeds is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Peerfeeds is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Peerfeeds; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
  
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Peerfeeds
{
    public partial class Feed : Form
    {
        public Feed()
        {
            InitializeComponent();
            OnLoad();
        }

        // if we're editing a feed
        public Xml.Feed editFeed;

        // define delegate
        public delegate void PassControl(object sender);

        // create instance (null)
        public PassControl passControl;

        private void OnLoad()
        {
            // Fill cmbFeedTemplate with available templates
            
            DirectoryInfo di = new DirectoryInfo("templates");
            FileInfo[] rgFiles = di.GetFiles("*.template");

            foreach (FileInfo fi in rgFiles)
            {
                cmbFeedTemplate.Items.Add(fi.Name);
            }

            if (editFeed != null)
            {
                txtFeedName.Text = editFeed.textCommand;
            }
        }

        private void btnFeedAdd_Click(object sender, EventArgs e)
        {
            string text = txtFeedURL.Text.Trim();

            if (!String.IsNullOrEmpty(text))
            {
                lstFeedList.Items.Add(txtFeedURL.Text);
                txtFeedURL.Clear();
            }
        }

        private void btnFeedCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnFeedSave_Click(object sender, EventArgs e)
        {
            SaveFeed();
        }

        private void SaveFeed()
        {
            string error = "Function not implemented yet.";

            if (error.Length <= 0)
            {
                this.Close();
            }
            else
            {
                DialogResult dr = MessageBox.Show(error, "Failed to save feed", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                if (dr == DialogResult.Retry)
                {
                    SaveFeed();
                }
            }
        }

        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            while(lstFeedList.SelectedItems.Count > 0)
            {
                lstFeedList.Items.Remove(lstFeedList.SelectedItem);
            }
        }

    }
}